var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var time = 0;
var touchDot = 0;//触摸时的原点
var interval = "";
Page({
  data: {
    goodsList: [],
    pageSize:10,
    pageNo:1,
    hasMore:true,
  },
  onLoad: function (options) {
    
    this.getGoodsList()

  },
  onPullDownRefresh: function () {
      this.getGoodsList()
  },
  onReady: function () {
    // 页面渲染完成
  },
  onReachBottom: function(){
      this.loadMore()
  },
  onShow: function () {
    // 页面显示
    if(this.data.id==1){
      wx.setNavigationBarTitle({title: '爆款推荐'})
    }
  },
  onHide: function () {
    // 页面隐藏
  },
  getCartNum:function(){
    let _this = this;
    util.request(api.cartUrl.cartList).then((res) =>{
      _this.setData({
        cartNum:res.result.count
      })
    });
  },
  loadMore: function(status) {
      var that = this;
      if (!this.data.hasMore) return
      wx.showLoading({
          title: '加载中...',
      })
      util.request(api.wholesaler.wholesalerList, {
          current: ++that.data.pageNo ,
          size:that.data.pageSize},'post').then(res=>{
              that.setData({
                goodsList: that.data.goodsList.concat(res.result)
              });
              if (res.result.length < that.data.pageSize) {
                  that.setData({
                      hasMore: false,
                  })
              }
              wx.hideLoading()
      }).catch(err=>{
          console.log(err)
      })
  },
  getGoodsList: function(){
      let _this = this;
      wx.showLoading({
        title: '加载中...',
      })
      _this.setData({
          pageNo: 1,
          hasMore:true
      });
      util.request(api.wholesaler.wholesalerList, {
          current: _this.data.pageNo ,
          size:_this.data.pageSize},'post').then(res=>{
          _this.setData({
              goodsList:res.result
          })
          if (res.result.length < _this.data.pageSize) {
              _this.setData({
                  hasMore: false,
              })
          }
          wx.stopPullDownRefresh();
          wx.hideLoading()
      }).catch(err=>{
          console.log(err)
      })
  },
  onUnload: function () {
    // 页面关闭
  }
})